package cn.lfzj.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.lfzj.dao.BusLineDao;
import cn.lfzj.model.BusLine;

@Service
public class BusLineService {
	@Autowired
	private BusLineDao busLineDao;

	/**
	 * 查询全部线路
	 */
	public List<BusLine> findAll() {
		return busLineDao.findAll();
	}

	/**
	 * 新增线路
	 */
	public int addBusLine(BusLine busLine) {
		if (busLineDao.find(busLine) != null) {
			return 2;
		}
		return busLineDao.addBusLine(busLine);
	}

	/**
	 * 删除线路
	 */
	public int delBusLine(int lineId) {
		return busLineDao.delBusLine(lineId);
	}

	/**
	 * 修改线路
	 */
	public int updBusLine(BusLine busLine) {
		BusLine result = busLineDao.find(busLine);
		if (result != null && busLine.getLineId() != result.getLineId()) {
			return -1;
		} else if (result != null && busLine.getLineId() == result.getLineId()) {
			return -2;
		}
		return busLineDao.updBusLine(busLine);
	}

	/**
	 * 根据ID查线路
	 */
	public BusLine selById(int lineId) {
		return busLineDao.selById(lineId);
	}

}
